package com.random.sort;

import java.lang.reflect.Array;
import java.util.*;

/**
 * @Author: YLTDMenglc
 * @Date: 2019/11/29
 * @Time: 15:59
 * @Description:
 */
public class RandomSortGroup {

    public List<List> randomGroup(){
        List<List> resultList = new ArrayList<List>();

        TwoList twoList = new TwoList();
        List<List> lists = twoList.bgList();
        List boyList = lists.get(0);
        List girlList = lists.get(1);
        // 1、随机排序
        Collections.shuffle(boyList);
        Collections.shuffle(girlList);
        System.out.println("分组前boyList："+boyList);
        System.out.println("分组前girlList:"+girlList);

        int group = 4;
        int typeNum = 2;
        // 2、男女分组
        List list1 = new ArrayList();
        List list2 = new ArrayList();
        List list3 = new ArrayList();
        for(int i = 0;i<group;i++){
            if(i < 3){
                for(int j = 0;j<boyList.size();j++){
                    if(list1.size() < typeNum){
                        list1.add(boyList.get(j));
                        boyList.remove(boyList.get(j));
                    }
                }
                for(int m = 0;m<girlList.size();m++){
                    if(list2.size() < typeNum){
                        list2.add(girlList.get(m));
                        girlList.remove(girlList.get(m));
                    }
                }
                list1.addAll(list2);
            } else {
                list3.addAll(boyList);
                list3.addAll(girlList);
                list1.addAll(list3);
            }
            // 去重
            Set set = new HashSet<>(list1);
            list1.clear();
            list2.clear();

            List arrayList = new ArrayList<>(set);
            resultList.add(arrayList);
        }
        return resultList;
    }
}
